import { ComponentType } from '@/plugins/form-render/constants/component-types';
import { IGaeaSetting } from '../../defines/application';
import { PermissionFields } from '../../types';

declare type DateMode = 'year' | 'month' | 'date' | 'time'; // 统一的 在pc的组件内需要进行抓换
export type PCDateMode = 'year' | 'month' | 'date' | 'time';

interface ChildrenData {
  $$typeof?: any;
  key?: string;
  props: ChildrenProps;
  ref?: any;
  type?: any;
  _owner?: any;
  _store?: any;
}
interface ChildrenProps {
  code: string;
  createType: string;
  customCode: any;
  data: any;
  disabled: any;
  instanceKey: string;
  layout: string;
  mode: string;
  name: string;
  onCallback: any;
  parentInstanceKey: string;
  placeholder: string;
  rangeFlag: string;
  renderMode: FormRenderModes;
  required: boolean;
  form?: any;
  rows: any;
  type: string;
  viewport: any;
}
export class Props {
  public editSetting: IGaeaSetting = {
    key: 'gaea-rangepicker',
    name: 'RangePicker',
    grouping: 'dateType',
    isBasicGroup: true,
    editors: [
      {
        field: '$$start.name',
        text: 'Label1',
        type: 'string',
        specialType: 'title'
      },
      {
        field: '$$end.name',
        text: 'Label2',
        type: 'string',
        specialType: 'title'
      },
      {
        field: '$$start.placeholder;$$end.placeholder',
        text: 'Placeholder',
        type: 'string'
      },
      {
        field: '$$start.mode;$$end.mode;',
        text: 'DateMode',
        type: 'select',
        data: [
          // {
          //   text: '年',
          //   value: 'year',
          // },
          // {
          //   text: '年-月',
          //   value: 'month',
          // },
          {
            text: '年-月-日',
            value: 'date'
          },
          {
            text: '年-月-日 时:分',
            value: 'time'
          }
        ]
      },
      {
        text: 'Validate',
        type: 'group',
        data: [
          {
            field: '$$children.required',
            text: 'Required',
            type: 'boolean'
          }
        ]
      },
      {
        text: 'Duration',
        type: 'group',
        data: [
          {
            field: 'isAutoCalc',
            text: 'AutoCalc',
            type: 'boolean'
          }
        ]
      },
      {
        field: '$$days.originName',
        text: 'Label3',
        type: 'string',
        specialType: 'title',
        visibleCondition: (itemProps: any) => {
          return itemProps.isAutoCalc;
        }
      },
      {
        devMode: true,
        group: 'Advanced', // 分组 --- 高级设置 or 基础设置(默认)
        field: '$$start.customCode',
        text: 'CustomCode1',
        type: 'string'
      },
      {
        devMode: true,
        group: 'Advanced', // 分组 --- 高级设置 or 基础设置(默认)
        field: '$$end.customCode',
        text: 'CustomCode2',
        type: 'string'
      },
      {
        devMode: true,
        group: 'Advanced', // 分组 --- 高级设置 or 基础设置(默认)
        field: '$$days.customCode',
        text: 'CustomCode3',
        type: 'string',
        visibleCondition: (itemProps: any) => {
          return itemProps.isAutoCalc;
        }
      },
      {
        group: 'Advanced', // 分组 --- 高级设置 or 基础设置(默认)
        field: 'visibleConditions',
        text: 'Condition',
        type: 'Condition'
      }
    ],
    /**
     * 控件组中内置rangePicker需要给rangePicker的子控件传参的时候，
     * 使用childProps:{start:{props:xxx},end:{props:xxx}}
     */
    components: [
      {
        key: ComponentType.DatePicker,
        groupItemKey: 'start',
        props: { name: '开始时间', rangeFlag: 'start' }
      },
      {
        key: ComponentType.DatePicker,
        groupItemKey: 'end',
        props: { name: '结束时间', rangeFlag: 'end' }
      },
      {
        key: ComponentType.InputNumber,
        groupItemKey: 'days',
        props: {
          originName: '时长',
          rangeFlag: 'days',
          placeholder: '自动计算'
        }
      }
    ]
  };

  public placeholder = '请选择'; // 控件提示语
  public isAutoCalc = true;
  public onRangeDateChange?: (params: any) => void;
  public children: ChildrenData[] = [];
  public form?: any;
  public readonly?: any;
  public disabled?: boolean;
  public permission?: PermissionFields;
  public formValues?: any;
  public visibleConditions?: any;
  public renderMode?: string;
  public code?: any;
}

export class State {
  public startTime?: number;
  public endTime?: number;
}
